package sort.impl;

import anaydis.sort.SorterType;
import com.sun.istack.internal.NotNull;

import java.util.Comparator;
import java.util.List;

public class SelectionSorter extends AbstractSorter {

    public SelectionSorter() {
        super(SorterType.SELECTION);
    }

    public <T> void sort(@NotNull Comparator<T> tComparator, @NotNull List<T> ts) {
        int min;
        for (int i = 0; i < ts.size(); i++) {
            min = i;
            for (int j = i + 1; j < ts.size(); j++) {
                if (greater(tComparator, ts, min, j)) {
                    min = j;
                }
            }
            if (min != i) {
                swap(ts, min, i);
            }
        }
    }
}
